import React, { Component } from 'react'
import { Table, Modal, message, Space, Tooltip, Button, Upload } from 'antd'
import {
  PlusOutlined,
  DownloadOutlined,
  UploadOutlined,
  EditOutlined,
  DeleteOutlined,
  SwapOutlined,
  DeleteFilled,
  InboxOutlined,
} from '@ant-design/icons'
import 'antd/dist/antd.css'
import moment from 'moment'
import 'moment/locale/zh-cn'
import {
  getDictionaryLabel,
  getAjaxurl,
} from '../../rudexRou/OperatesCookie.js'
import { getDeptByCode } from '../../utils/index.js'
import AdvancedSearchForm from '../../componentJsx/common/searchForm'
import HasPermi from '../../componentJsx/common/hasPermi'
import EditForm from '../../componentJsx/common/editForm'
import '../../componentCss/component.css'
import { confirmDeptByCode } from '../../utils'

// import { Excel } from 'exceljs'
import { v4 as uuidv4 } from 'uuid'
import {
  addArchives,
  getTrustedArchives,
  getTrustedSearch,
  deleteArchives,
  updateRiskInformation,
  exportRisk,
  createDownloadExcel,
  exportExcelOr,
  exportExcel,
  updateArchives,
} from '../../api'
class Record extends Component {
  constructor(props) {
    super(props)
    this.state = {
      loading: false,
      total: 0,
      pageSize: 10,
      page: 1,
      isEditVisible: false, // 修改模态框状态
      isMoveVisible: false, // 移出风险区模态框状态
      isDelVisible: false, // 删除模态框状态
      uploadModalVisible: false,
      confirmLoading: false, //确认按钮异步等待
      modelTitle: '', // 模态框名称
      dataList: [], // 表格数据
      searchParams: {}, // 查询条件
      // 表格列配置
      columns: [
        {
          fixed: 'left',
          title: '工号',
          dataIndex: 'jobNumber',
          key: 'jobNumber',
          width: 80,
        },
        {
          fixed: 'left',
          title: '姓名',
          dataIndex: 'name',
          key: 'name',
          width: 80,
        },
        {
          title: '地域',
          dataIndex: 'regional',
          key: 'regional',
          ellipsis: true,
          width: 100,
          render: (text) =>
            text ? getDictionaryLabel('addressConfig', text) : text,
        },
        {
          title: '部门BD',
          dataIndex: 'departmentBD',
          key: 'departmentBD',
          width: 180,
          ellipsis: true,
        },
        {
          title: '部门BU',
          dataIndex: 'departmentBU',
          key: 'departmentBU',
          width: 180,
          ellipsis: true,
        },
        {
          title: '部门CU',
          dataIndex: 'departmentCU',
          key: 'departmentCU',
          width: 180,
          ellipsis: true,
        },
        // {
        //   title: '当前状态',
        //   dataIndex: 'theCurrentState',
        //   key: 'theCurrentState',
        //   width: 80,
        //   ellipsis: true,
        // },
        {
          title: '是否转正',
          dataIndex: 'yesOrNoPositive',
          key: 'yesOrNoPositive',
          width: 80,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('isProbation', text) : text,
        },
        {
          title: '办公地类型',
          dataIndex: 'typeOfOffice',
          key: 'typeOfOffice',
          width: 100,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('officeType', text) : text,
        },
        {
          title: '办公地',
          dataIndex: 'office',
          key: 'office',
          width: 80,
          ellipsis: true,
        },
        {
          title: '软通邮箱',
          dataIndex: 'email',
          key: 'email',
          width: 100,
          ellipsis: true,
        },
        {
          title: '是否入OMP',
          dataIndex: 'yesOrNoOmp',
          key: 'yesOrNoOmp',
          width: 100,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('yesOrNoOmp', text) : text,
        },
        {
          title: '华为工号',
          dataIndex: 'huaWeiJobNomber',
          key: 'huaWeiJobNomber',
          width: 80,
          ellipsis: true,
        },
        {
          title: '华为邮箱',
          dataIndex: 'partyEmail',
          key: 'partyEmail',
          width: 80,
          ellipsis: true,
        },
        {
          title: '是否涉及代码',
          dataIndex: 'yesOrNoCode',
          key: 'yesOrNoCode',
          width: 110,
          ellipsis: true,
          render: (text) => (text ? getDictionaryLabel('yesOrNo', text) : text),
        },
        {
          title: '风险信息',
          dataIndex: 'riskInformation',
          key: 'riskInformation',
          width: 80,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('riskInfo', text) : text,
        },
        {
          title: '岗位类型',
          dataIndex: 'postType',
          key: 'postType',
          width: 80,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('postCategory', text) : text,
        },
        {
          title: '主开发语言',
          dataIndex: 'firstResearch',
          key: 'firstResearch',
          width: 100,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('language', text) : text,
        },
        {
          title: '次开发语言',
          dataIndex: 'secondaryResearch',
          key: 'secondaryResearch',
          width: 100,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('language', text) : text,
        },
        {
          title: 'MR评定次数',
          dataIndex: 'evaluationNumberMR',
          key: 'evaluationNumberMR',
          width: 110,
          ellipsis: true,
        },

        {
          title: '最近评定时间',
          dataIndex: 'listEvaluateTime',
          key: 'listEvaluateTime',
          width: 110,
          ellipsis: true,
          render: (text) => (text ? moment(text).format('YYYY-MM-DD') : text),
        },
        {
          title: '最近评定结果',
          dataIndex: 'listEvaluateResult',
          key: 'listEvaluateResult',
          width: 110,
          ellipsis: true,
          render: (text) =>
            text ? getDictionaryLabel('reviewResult', text) : text,
        },
        {
          title: '新员工导师',
          dataIndex: 'tutor',
          key: 'tutor',
          width: 100,
          ellipsis: true,
        },
        {
          title: '项目经理',
          dataIndex: 'pm',
          key: 'pm',
          ellipsis: true,
          width: 80,
        },
        {
          title: '代码守护者',
          dataIndex: 'codeGuardian',
          key: 'codeGuardian',
          width: 100,
          ellipsis: true,
        },
        {
          title: '是否参加可信训战营',
          dataIndex: 'yesOrNoCredible',
          key: 'yesOrNoCredible',
          width: 150,
          ellipsis: true,
          render: (text) => (text ? getDictionaryLabel('yesOrNo', text) : text),
        },
        {
          title: '入营时间',
          dataIndex: 'joinCredibleTime',
          key: 'joinCredibleTime',
          width: 110,
          ellipsis: true,
        },
        {
          title: '出营时间',
          dataIndex: 'outCredibleTime',
          key: 'outCredibleTime',
          width: 110,
          ellipsis: true,
        },
        {
          title: '是否通过',
          dataIndex: 'yesOrNoAdopt',
          key: 'yesOrNoAdopt',
          width: 80,
          ellipsis: true,
          render: (text) => (text ? getDictionaryLabel('yesOrNo', text) : text),
        },
        {
          title: '最近修改人',
          dataIndex: 'updateUser',
          key: 'updateUser',
          ellipsis: true,
          width: 110,
          ellipsis: true,
        },
        {
          title: '最近修改时间',
          dataIndex: 'listModifyTime',
          key: 'listModifyTime',
          ellipsis: true,
          width: 160,
          ellipsis: true,
          render: (text) =>
            text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : text,
        },
        {
          fixed: 'right',
          title: '操作',
          key: 'action',
          width: 80,
          render: (text, record) => (
            <Space size="middle">
              <Tooltip title="编辑">
                <div style={{ width: 30 }}>
                  <HasPermi
                    bottonData={{
                      type: 'link',
                      interceptor: 'tmfs:record:add',
                      clickFn: () => this.editItem(record),
                      icon: <EditOutlined />,
                    }}
                  />
                </div>
              </Tooltip>
            </Space>
          ),
        },
      ],
      bottonList: [
        {
          interceptor: 'tmfs:record:add',
          type: 'primary',
          clickFn: this.addModal,
          icon: <PlusOutlined />,
          text: '新增',
        },
        {
          interceptor: 'tmfs:record:del',
          type: 'danger',
          clickFn: this.showDelModal,
          icon: <DeleteOutlined />,
          text: '删除',
        },
        {
          interceptor: 'tmfs:record:pushRisk',
          clickFn: this.showMoveModal,
          icon: <SwapOutlined />,
          text: '移入风险区',
        },
      ],
      bottonListRight: [
        {
          interceptor: 'tmfs:record:import',
          icon: <UploadOutlined />,
          clickFn: () => this.showImportModal(null),
          text: '导入',
        },
        {
          interceptor: 'tmfs:record:export',
          icon: <DownloadOutlined />,
          clickFn: this.excelPort,
          text: '导出',
        },
      ],
      // 查询条件项配置
      searchForm: [
        {
          type: 'input',
          name: '员工工号',
          code: 'jobNumber',
          maxLength: 20,
          placeholder: '请输入员工工号',
        },
        {
          type: 'input',
          name: '员工姓名',
          code: 'name',
          maxLength: 20,
          placeholder: '请输入员工姓名',
        },
        {
          type: 'select',
          name: '地域',
          code: 'region',
          options: getDictionaryLabel('addressConfig'),
        },
        {
          type: 'cascader',
          name: '部门',
          code: 'dept',
          options: JSON.parse(
            localStorage.getItem('deptList')
              ? localStorage.getItem('deptList')
              : '[]'
          ),
        },
        // {
        //   type: 'select',
        //   name: '风险信息',
        //   code: 'yesOrNoRisk',
        //   options: getDictionaryLabel('riskInfo'),
        // },
      ],
      selectedRowKeys: [], // 选择行Key集合
      selectedRows: [], // 选择行集合
      selectedRow: {}, // 修改行数据
      // 新增数据配置
      editFormConfig: [],
      // 备选人员数据
      // empList: JSON.parse(localStorage.getItem('empList')),
      searchEmpList: [], // 新增时的人员备选列表
      config: {},
      userInfo: JSON.parse(localStorage.getItem('userInfo')),
    }
  }
  componentWillMount() {}
  componentDidMount() {
    this.getData()
  }
  editItem = (item) => {
    const editFormConfig = [
      {
        type: 'text',
        name: '员工工号',
        code: 'jobNumberStr',
        half: true,
      },
      {
        type: 'text',
        name: '部门BD',
        code: 'departmentBD',
        half: true,
      },
      {
        type: 'text',
        name: '员工姓名',
        code: 'nameStr',
        half: true,
      },
      {
        type: 'text',
        name: '部门BU',
        code: 'departmentBU',
        half: true,
      },
      {
        type: 'text',
        name: '地域',
        code: 'regional',
        half: true,
        dictionaryCode: 'addressConfig',
      },
      {
        type: 'text',
        name: '部门CU',
        code: 'departmentCU',
        half: true,
      },
      {
        type: 'text',
        name: '是否转正',
        code: 'yesOrNoPositive',
        half: true,
      },
      {
        type: 'text',
        name: '软通邮箱',
        code: 'email',
        half: true,
      },
      {
        type: 'select',
        name: '办公地类型',
        code: 'typeOfOffice',
        half: true,
        options: getDictionaryLabel('officeType'),
      },
      {
        type: 'input',
        name: '办公地',
        code: 'office',
        maxLength: 50,
        half: true,
      },
      {
        type: 'input',
        name: '华为工号',
        code: 'huaWeiJobNomber',
        maxLength: 20,
        half: true,
      },
      {
        type: 'input',
        name: '华为邮箱',
        code: 'partyEmail',
        maxLength: 50,
        half: true,
      },
      {
        type: 'radio',
        name: '是否入OMP',
        code: 'yesOrNoOmp',
        half: true,
        options: getDictionaryLabel('yesOrNoOmp'),
      },
      {
        name: '新员工导师',
        type: 'input',
        code: 'tutor',
        maxLength: 20,
        half: true,
      },
      {
        name: '项目经理',
        type: 'input',
        code: 'pm',
        maxLength: 20,
        half: true,
      },
      {
        name: '代码守护者',
        type: 'input',
        code: 'codeGuardian',
        maxLength: 20,
        half: true,
      },
      {
        name: '是否参加可信训战营',
        type: 'radio',
        code: 'yesOrNoCredible',
        half: true,
        options: getDictionaryLabel('yesOrNo'),
      },
      {
        name: '入营时间',
        type: 'datePicker',
        code: 'joinCredibleTime',
        half: true,
      },
      {
        name: '出营时间',
        type: 'datePicker',
        code: 'outCredibleTime',
        half: true,
      },
      {
        type: 'radio',
        name: '是否通过',
        code: 'yesOrNoAdopt',
        half: true,
        options: getDictionaryLabel('yesOrNo'),
      },
      {
        type: 'radio',
        name: '是否涉及代码',
        code: 'yesOrNoCode',
        half: true,
        options: getDictionaryLabel('yesOrNo'),
      },
      {
        type: 'select',
        name: '岗位类型',
        code: 'postType',
        half: true,
        options: getDictionaryLabel('postCategory'),
      },
      {
        type: 'select',
        name: '主开发语言',
        code: 'firstResearch',
        half: true,
        options: getDictionaryLabel('language'),
      },
      {
        type: 'select',
        name: '次开发语言',
        code: 'secondaryResearch',
        half: true,
        options: getDictionaryLabel('language'),
      },
      {
        type: 'input',
        name: '工号',
        code: 'jobNumber',
        half: true,
        hidden: true,
      },
      {
        type: 'input',
        name: '员工姓名',
        code: 'name',
        half: true,
        hidden: true,
      },
    ]
    this.setState({ editFormConfig: editFormConfig })
    const updateInfo = {
      departmentBD: item.departmentBD,
      departmentBU: item.departmentBU,
      departmentCU: item.departmentBU,
      email: item.email,
      regional: item.regional
        ? getDictionaryLabel('addressConfig', item.regional)
        : item.regional,
      nameStr: item.name,
      yesOrNoPositive: item.yesOrNoPositive
        ? getDictionaryLabel('isProbation', item.yesOrNoPositive)
        : item.yesOrNoPositive,
      yesOrNoOmp: item.yesOrNoOmp,
      jobNumberStr: item.jobNumber,
      jobNumber: item.jobNumber,
      name: item.name,
      typeOfOffice: item.typeOfOffice,
      office: item.office,
      huaWeiJobNomber: item.huaWeiJobNomber,
      partyEmail: item.partyEmail,
      tutor: item.tutor,
      pm: item.pm,
      codeGuardian: item.codeGuardian,
      yesOrNoCredible: item.yesOrNoCredible,
      joinCredibleTime: item.joinCredibleTime
        ? moment(new Date(item.joinCredibleTime))
        : item.joinCredibleTime,
      outCredibleTime: item.outCredibleTime
        ? moment(new Date(item.outCredibleTime))
        : item.outCredibleTime,
      yesOrNoAdopt: item.yesOrNoAdopt,
      yesOrNoCode: item.yesOrNoCode,
      postType: item.postType,
      firstResearch: item.firstResearch,
      secondaryResearch: item.secondaryResearch,
    }
    this.setState(
      {
        selectedRow: updateInfo,
        editFormConfig: editFormConfig,
        isEditVisible: true,
        modelTitle: '修改',
      },
      () => {
        //填充88y选中行的数据
        this.editFormRef.setValues(updateInfo)
      }
    )
  }
  getData = () => {
    this.setState({ loading: true, dataList: [] })
    let isSearch = false
    for (var key in this.state.searchParams) {
      if (this.state.searchParams[key]) {
        isSearch = true
      }
    }
    if (isSearch) {
      getTrustedSearch([this.state.searchParams]).then((response) => {
        if (response.data.code === '200') {
          if (response.data && response.data.data) {
            const rsp = response.data.data
            this.setState({ total: rsp.length })
            this.setState({ dataList: rsp })
          }
        } else {
          message.error(response.data.message || '查询数据失败!')
        }
        this.setState({ loading: false, selectedRowKeys: [] })
      })
    } else {
      getTrustedArchives([this.state.searchParams]).then((response) => {
        if (response.data.code === '200') {
          if (response.data && response.data.data) {
            const rsp = response.data.data
            this.setState({ total: rsp.length })
            this.setState({ dataList: rsp })
          }
        } else {
          message.error(response.data.message || '查询数据失败!')
        }
        this.setState({ loading: false, selectedRowKeys: [] })
      })
    }
  }
  addModal = () => {
    const editFormConfig = [
      {
        type: 'search',
        name: '员工工号',
        code: 'jobNumber',
        options: [],
        rules: [
          {
            required: true,
            message: '请输入员工工号',
          },
        ],
      },
      {
        type: 'text',
        name: '员工工号',
        code: 'jobNumberStr',
        half: true,
      },
      {
        type: 'text',
        name: '部门BD',
        code: 'departmentBD',
        half: true,
      },
      {
        type: 'text',
        name: '员工姓名',
        code: 'nameStr',
        half: true,
      },
      {
        type: 'text',
        name: '部门BU',
        code: 'departmentBU',
        half: true,
      },
      {
        type: 'text',
        name: '地域',
        code: 'region',
        half: true,
        dictionaryCode: 'addressConfig',
      },
      {
        type: 'text',
        name: '部门CU',
        code: 'departmentCU',
        half: true,
      },
      {
        type: 'text',
        name: '是否转正',
        code: 'yesOrNoPositive',
        half: true,
      },
      {
        type: 'text',
        name: '软通邮箱',
        code: 'email',
        half: true,
      },
      {
        type: 'select',
        name: '办公地类型',
        code: 'typeOfOffice',
        half: true,
        options: getDictionaryLabel('officeType'),
      },
      {
        type: 'input',
        name: '办公地',
        code: 'office',
        maxLength: 50,
        half: true,
      },
      {
        type: 'input',
        name: '华为工号',
        code: 'huaWeiJobNomber',
        maxLength: 20,
        half: true,
      },
      {
        type: 'input',
        name: '华为邮箱',
        code: 'partyEmail',
        maxLength: 50,
        half: true,
      },
      {
        type: 'radio',
        name: '是否入OMP',
        code: 'yesOrNoOmp',
        half: true,
        options: getDictionaryLabel('yesOrNoOmp'),
      },
      {
        name: '新员工导师',
        type: 'input',
        code: 'tutor',
        maxLength: 20,
        half: true,
      },
      {
        name: '项目经理',
        type: 'input',
        code: 'pm',
        maxLength: 20,
        half: true,
      },
      {
        name: '代码守护者',
        type: 'input',
        code: 'codeGuardian',
        maxLength: 20,
        half: true,
      },
      {
        name: '是否参加可信训战营',
        type: 'radio',
        code: 'yesOrNoCredible',
        half: true,
        options: getDictionaryLabel('yesOrNo'),
      },
      {
        name: '入营时间',
        type: 'datePicker',
        code: 'joinCredibleTime',
        half: true,
      },
      {
        name: '出营时间',
        type: 'datePicker',
        code: 'outCredibleTime',
        half: true,
      },
      {
        type: 'radio',
        name: '是否通过',
        code: 'yesOrNoAdopt',
        half: true,
        options: getDictionaryLabel('yesOrNo'),
      },
      {
        type: 'radio',
        name: '是否涉及代码',
        code: 'yesOrNoCode',
        half: true,
        options: getDictionaryLabel('yesOrNo'),
      },
      {
        type: 'select',
        name: '岗位类型',
        code: 'postType',
        half: true,
        options: getDictionaryLabel('postCategory'),
      },
      {
        type: 'select',
        name: '主开发语言',
        code: 'firstResearch',
        half: true,
        options: getDictionaryLabel('language'),
      },
      {
        type: 'select',
        name: '次开发语言',
        code: 'secondaryResearch',
        half: true,
        options: getDictionaryLabel('language'),
      },
      {
        type: 'input',
        name: '软通邮箱',
        code: 'name',
        half: true,
        hidden: true,
      },
    ]
    this.setState(
      {
        editFormConfig: editFormConfig,
        isEditVisible: true,
        modelTitle: '新增',
      },
      () => {
        //填充当前选中行的数据
        this.editFormRef.setValues({
          typeOfOffice: 'on',
          yesOrNoOmp: '0',
          yesOrNoCredible: 'Y',
          yesOrNoAdopt: 'Y',
          yesOrNoCode: 'Y',
          postType: '1',
          firstResearch: '1',
          secondaryResearch: '1',
        })
      }
    )
  }
  showMoveModal = () => {
    if (this.state.selectedRowKeys.length === 0) {
      return message.warning('请勾选需要操作的记录!')
    }
    this.setState({ isMoveVisible: true })
  }
  handleMoveOk = () => {
    this.buttonLoading(true)
    const list = this.state.selectedRows.map((item) => {
      return {
        jobNumber: item.jobNumber,
      }
    })
    updateRiskInformation(list).then((response) => {
      if (response.data.code === '200') {
        message.success('操作成功!')
        this.getData()
      } else {
        message.error(response.data.message || '操作失败!')
      }
      this.setState({ isMoveVisible: false })
      this.buttonLoading(false)
    })
  }
  showDelModal = () => {
    if (this.state.selectedRowKeys.length === 0) {
      return message.warning('请勾选需要操作的记录!')
    }
    this.setState({ isDelVisible: true })
  }
  handleDelOk = () => {
    this.buttonLoading(true)
    const list = this.state.selectedRows.map((item) => {
      return {
        jobNumber: item.jobNumber,
      }
    })
    deleteArchives(list).then((response) => {
      if (response.data.code === '200') {
        message.success('操作成功!')
        this.getData()
      } else {
        message.error(response.data.message || '操作失败!')
      }
      this.setState({ isDelVisible: false })
      this.buttonLoading(false)
    })
  }
  handleEditOk = () => {
    this.editFormRef
      .validateFields()
      .then(() => {
        this.buttonLoading(true)
        const info = this.editFormRef.getValues(true)
        info.outCredibleTime = info.outCredibleTime
          ? moment(info.outCredibleTime).format('YYYY-MM-DD')
          : info.outCredibleTime
        info.joinCredibleTime = info.joinCredibleTime
          ? moment(info.joinCredibleTime).format('YYYY-MM-DD')
          : info.joinCredibleTime
        info.updateUser = this.state.userInfo.empName
        info.listModifyTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
        updateArchives([info]).then((response) => {
          if (response.data.code === '200') {
            message.success('操作成功!')
            this.getData()
          } else {
            message.error(response.data.message || '操作失败!')
          }
          this.setState({ isEditVisible: false })
          this.buttonLoading(false)
          this.editFormRef.resetFields()
        })
      })
      .catch(() => {})
  }
  handleCancel = () => {
    this.setState({
      isMoveVisible: false,
      isEditVisible: false,
      isDelVisible: false,
      uploadModalVisible: false,
    })
    if (this.state.isEditVisible) {
      this.editFormRef.resetFields()
    }
  }
  execSearch = (data) => {
    const param = {}
    const deptList = data.dept ? JSON.parse(JSON.stringify(data.dept)) : null
    delete data.dept
    const code = deptList ? deptList.pop() : []
    const item = confirmDeptByCode(code)
    if (item && item.type === 'bd') {
      param.departmentBD = item.value
    }
    if (item && item.type === 'bu') {
      param.departmentBU = item.value
    }
    if (item && item.type === 'cu') {
      param.departmentCU = item.value
    }

    for (var key in data) {
      if (data[key]) {
        param[key] = data[key]
      }
    }
    this.setState({ searchParams: param })
    this.getData()
  }
  onRef = (ref) => {
    this.editFormRef = ref
  }
  changeUserInfo = (data) => {
    const probationPeriod = data.probationPeriod
      ? getDictionaryLabel('isProbation', data.probationPeriod)
      : ''
    this.editFormRef.setValues({
      jobNumber: data.empNo,
      jobNumberStr: data.empNo,
      name: data.empName,
      nameStr: data.empName,
      departmentBD: data.orgBdName,
      departmentBU: data.orgBuName,
      departmentCU: data.orgCuName,
      region: data.regionName,
      yesOrNoPositive: probationPeriod,
      email: data.email,
    })
  }
  queryAuth() {
    return true
  }
  //设置按钮加载动画开关
  buttonLoading = (flag) => {
    this.setState({ confirmLoading: flag })
  }
  excelPort = () => {
    if (this.state.selectedRowKeys && this.state.selectedRowKeys.length > 0) {
      const data = JSON.parse(JSON.stringify(this.state.selectedRows))
      data.forEach((item) => {
        item.regional = item.regional
          ? getDictionaryLabel('addressConfig', item.regional)
          : ''
      })
      exportExcelOr(data).then((response) => {
        if (response.data.code === '200') {
          message.success('创建导出任务成功，请稍后在导入导出结果页面查看数据')
        } else {
          message.error(response.data.message || '创建导出任务失败!')
        }
      })
    } else {
      const excelName = uuidv4()
      createDownloadExcel(excelName).then((response) => {
        if (response.data.code === '200') {
          message.success('创建导出任务成功，请稍后在导入导出结果页面查看数据')
          const id = response.data.msg
          exportExcel(excelName, id).then((resp) => {
            // if (resp.data.code === '200') {
            //   message.success(
            //     '创建导出任务成功，请稍后在导入导出结果页面查看数据'
            //   )
            // } else {
            //   message.error(resp.data.message || '创建导出任务失败!')
            // }
          })
        } else {
          message.error(response.data.message || '导出失败!')
        }
      })
    }
  }
  // 下载模板
  downloadTemplate = () => {
    exportRisk(`/tmfs/trusted/archives/download`, '可信档案导入模板.xlsx')
  }
  showImportModal = () => {
    this.setState({ uploadModalVisible: true })
  }
  //修改页数changePage
  changePage = (page, pageSize) => {
    this.setState({
      page,
      pageSize,
    })
  }
  render() {
    const rowSelection = {
      selectedRowKeys: this.state.selectedRowKeys,
      onChange: (selectedRowKeys: React.Key[], selectedRows: DataType[]) => {
        this.setState({
          selectedRows: selectedRows,
          selectedRowKeys: selectedRowKeys,
        })
      },
      getCheckboxProps: (record: DataType) => ({
        disabled: record.name === 'Disabled User', // Column configuration not to be checked
        name: record.name,
      }),
    }
    let authToken = window.localStorage.getItem('authToken')
    let token = window.localStorage.getItem('refreshToken')
    const url = getAjaxurl() + '/tmfs/trusted/archives/importExcel'
    const importProps = {
      action: url,
      name: 'mFile',
      accept: '.xlsx',
      headers: {
        refreshToken: token,
        authToken: authToken,
      },
      // beforeUpload(file) {
      //   var workbook = new Excel.Workbook()
      //   let status = false
      //   const asy = function() {
      //     return new Promise((resolve, reject) => {
      //       workbook.xlsx.load(file).then(function() {
      //         let temp = false
      //         workbook.eachSheet(function(worksheet, sheetId) {
      //           console.log('sheetId===', sheetId)
      //           console.log('rowCount:', worksheet.rowCount)
      //           if (worksheet.rowCount > 1002) {
      //             temp = true
      //           }
      //         })
      //         resolve(temp)
      //       })
      //     })
      //   }
      //   const add = async function() {
      //     const a = await asy()
      //     console.log('ssssssssssss', a)
      //     return a
      //   }
      //   console.log('add：', add())
      //   console.log('file:', file)
      //   return status
      // },
      onChange(info) {
        const { status } = info.file
        if (status !== 'uploading') {
        }
        if (status === 'done') {
          if (info.file.response.code == 200) {
            message.success(`${info.file.name} 导入成功`)
          } else if (info.file.response.code == 500) {
            message.error(
              info.file.response.message || `${info.file.name} 导入失败`
            )
          } else {
            message.error(
              info.file.response.message || `${info.file.name} 导入失败`
            )
          }
        } else if (status === 'error') {
          message.error(`${info.file.name}  上传失败`)
        }
      },
    }
    return (
      <div>
        <div className="myProjectsBody">
          <div className="tabstyle">
            <div className="bigContent1" id="projectDetail">
              <AdvancedSearchForm
                execSearch={this.execSearch}
                formData={this.state.searchForm}
              />
            </div>
          </div>
          <div className="segmentationDiv" />
          <div className="tabstyle">
            <div className="bigContent1" id="projectDetail">
              <div className="operatingDiv">
                {this.state.bottonList.map((item) => (
                  <HasPermi key={item.interceptor} bottonData={item} />
                ))}
                <div className="right">
                  {this.state.bottonListRight.map((item) => (
                    <HasPermi key={item.interceptor} bottonData={item} />
                  ))}
                </div>
              </div>
              <div className="tableDiff">
                <Table
                  rowSelection={{
                    type: 'checkbox',
                    ...rowSelection,
                  }}
                  loading={this.state.loading}
                  dataSource={this.state.dataList}
                  scroll={{ x: '100vw' }}
                  bordered
                  columns={this.state.columns}
                  rowKey={(record) => record.jobNumber}
                  pagination={{
                    total: this.state.total,
                    pageSize: this.state.pageSize,
                    current: this.state.page,
                    showSizeChanger: true,
                    onChange: this.changePage,
                    showTotal: (total) => '共 ' + total + ' 条',
                  }}
                ></Table>
              </div>
            </div>
          </div>
        </div>
        <Modal
          title="移入风险区"
          type="primary"
          okText="确认"
          cancelText="取消"
          visible={this.state.isMoveVisible}
          onOk={this.handleMoveOk}
          onCancel={this.handleCancel}
        >
          请确认是否将数据移入风险区？
        </Modal>
        <Modal
          width="500px"
          title="删除提示"
          visible={this.state.isDelVisible}
          onOk={() => this.handleDelOk()}
          confirmLoading={this.state.confirmLoading}
          onCancel={() => this.handleCancel()}
          cancelText="取消"
          okText="确认删除"
        >
          <DeleteFilled
            style={{
              fontSize: '28px',
              color: '#e00',
              float: 'left',
              backgroundColor: '#f002',
              padding: 8,
              borderRadius: '50%',
            }}
          />
          <div
            style={{
              fontSize: 14,
              marginLeft: 60,
              height: 22,
              lineHeight: '22px',
              color: '#666',
              fontWeight: 700,
            }}
          >
            删除所选数据？
          </div>
          <div
            style={{
              fontSize: 14,
              marginLeft: 60,
              height: 22,
              lineHeight: '22px',
              color: '#e00',
            }}
          >
            删除后数据不可恢复，请确认是否删除选中的档案信息？
          </div>
        </Modal>
        <Modal
          title={this.state.modelTitle}
          type="primary"
          okText="确认"
          cancelText="取消"
          width="900px"
          visible={this.state.isEditVisible}
          onOk={this.handleEditOk}
          onCancel={this.handleCancel}
          destroyOnClose={true}
          forceRender={true}
        >
          <EditForm
            onRef={this.onRef}
            formData={this.state.editFormConfig}
            changeUserInfo={this.changeUserInfo}
          />
        </Modal>
        <Modal
          destroyOnClose={true}
          width="500px"
          title="导入档案数据"
          visible={this.state.uploadModalVisible}
          onCancel={() => this.handleCancel()}
          footer={[
            <div key="btnBox" style={{ textAlign: 'center' }}>
              <Button key="cancel" onClick={() => this.handleCancel()}>
                取消
              </Button>
            </div>,
          ]}
        >
          <Upload.Dragger {...importProps}>
            <p className="ant-upload-drag-icon">
              <InboxOutlined />
            </p>
            <p className="ant-upload-text">单击或拖动文件到该区域进行上传</p>
            <p className="ant-upload-hint">
              一次只能导入单个文件，单次最大限制
              <span style={{ color: 'red' }}>1000</span>行。仅支持
              <span style={{ color: 'red' }}>.xlsx</span>
              格式
            </p>
          </Upload.Dragger>
          <Button type="link" onClick={this.downloadTemplate}>
            下载导入模板
          </Button>
        </Modal>
      </div>
    )
  }
}
export default Record
